home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48hor1 / bits.doc < prev    next >
Text File  |  1995-03-31  |  798b  |  25 lines

  1. (Comp.sys.handhelds) 
  2. Item: 2277 by jurjen at cwi.nl 
  3. Author: [Jurjen NE Bos] 
  4.   Subj: HP28/48: Hamming weight of binary number (BITS) 
  5.   Date: Fri Mar 01 1991 
  6.  
  7. Everybody who has had a HP16 knows that it sometimes is very convenient to 
  8. compute the number of 1 bits in a number. 
  9.  
  10. Computing this on a HP28 or HP48 seems to take some time.  A recent discussion 
  11. in comp.arch yielded a much more efficient solution.  I changed it a little 
  12. bit to make it work for 64 bits, and translated it into RPL.  The program is 
  13. shown below. 
  14.  
  15. Happy Hacking! 
  16.  
  17. BITS: 
  18. \<< # 7777777777777777h OVER SR OVER AND 
  19.   DUP2 SR AND ROT OVER SR AND + + - 
  20.   DUP SR SR SR SR + #F0F0F0F0F0F0F0Fh AND 
  21.   #FF DUP2 / * - 
  22. \>> 
  23.  
  24. I leave proving that this works as an exercise to the reader :-) 
  25.